<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>房屋出租管理系统</title>
    <script src="../res/js/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="../res/js/login_common.js" charset="utf-8"></script>
    <script src="../res/layui/layui.js" charset="utf-8"></script>
    <script src="../res/js/Tools.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../res/layui/css/layui.css" media="all">
    <style type="text/css">
        .informs {
            height: 50px;
            line-height: 55px;
            font-size: 20px;
            border-top: 1px solid #E6E6E6;
            cursor: pointer;
        }
    </style>
</head>
<body>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="see">查看</a>
    {{#
    if( window.loginObj.manager.userType < 2 ){
    }}
    <a class="layui-btn layui-btn-xs " lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    {{#
    }
    }}
</script>
<script type="text/html" id="toolbarDemo">
    {{#
    if( window.loginObj.manager.userType < 2 ){
    }}
    <div class="layui-btn-container">
        <button class="layui-btn" lay-event="update">修改</button>
        <button class="layui-btn layui-btn-danger" lay-event="delete">批量删除</button>
        <button class="layui-btn layui-btn-normal" lay-event="add">新增</button>
    </div>
    {{#
    }
    }}
</script>
<div class="jumbotron" style="margin: 0 30px; padding: 20px;">

    <div>
        <h2 align="center" style="margin-bottom: 10px">通知中心</h2>
    </div>
    <div id="inform" align="center">

    </div>
    <hr>
    <h2 align="center">业绩中心</h2>
    <form class="layui-form" action="">
        <div class="select">
            <div class="layui-inline">
                <label class="layui-form-label">员工名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="userName" id="userName" placeholder="请输入员工名称"
                           autocomplete="off"
                           class="layui-input" style="width: 150px">
                </div>
            </div>

            <div class="layui-input-inline">
                <label class="layui-form-label">
                    <input type="button" class="layui-btn layui-btn-normal" id="isAll" value="查询">
                </label>
            </div>
        </div>
    </form>
    <div>
        <table id="demo" lay-filter="test"></table>
    </div>
</div>
<script>
    var table2;
    layui.use('table', function () {
        var table = layui.table;
        //第一个实例
        table2 = table.render({
            elem: '#demo'
            , url: '../performanceAction/findAll' //数据接口
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , page: true //开启分页
            , totalRow: true
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {
                    type: 'numbers',
                    title: '序列',
                    fixed: 'left',
                    width: 75,
                    unresize: true,
                    sort: true,
                    totalRowText: '合计'
                }
                , {field: 'userName', title: '成交人', width: 100}
                , {field: 'houseName', title: '成交房源', width: 100}
                , {field: 'performanceMoney', title: '成交价格', width: 110, sort: true, totalRow: true}
                , {field: 'performanceBrokerage', title: '佣金', width: 110, sort: true, totalRow: true}
                , {field: 'clientPhone', title: '客户电话', width: 120}
                , {field: 'clientDivide', title: '客户分成', width: 110, sort: true, totalRow: true}
                , {field: 'userDivide', title: '成交人分成', width: 110, sort: true, totalRow: true}
                , {field: 'houseDivide', title: '房源分成', width: 110, sort: true, totalRow: true}
                , {field: 'fundDivide', title: '基金分成', width: 110, sort: true, totalRow: true}
                , {
                    field: 'performanceDate', title: '成交日期', width: 160, templet: function (row) {
                        if (row.performanceDate) {
                            return dateFormat("yyyy-MM-dd hh:mm:ss", new Date(row.performanceDate));
                        } else {
                            return "";
                        }
                    }
                }
                , {field: 'performanceRemark', title: '备注', width: 300}
                //,{field:'isva', title:'状态', width:150,toolbar:'#isva', width:100}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 200}
            ]]
        });

        $('#userName').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                event.preventDefault();
                //回车执行查询
                $('#isAll').click();
            }
        });

        $("#isAll").on("click", function () {
            table2.reload({
                where: {
                    userName: $("#userName").val()
                },
                page: {
                    curr: 1
                }
            })
        });

        //监听头工具栏事件
        table.on('toolbar(test)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id); //获取选中的数据
                switch (obj.event) {
                    case 'add':
                        //layer.msg('添加');
                        //var data = checkStatus.data;
                        //layer.alert(JSON.stringify(data));
                        //layer.msg('录入数据');
                        layer.open({
                            type: 2,
                            title: '业绩分成',
                            shadeClose: true,
                            shade: false,
                            maxmin: true, //开启最大化最小化按钮
                            area: ['90%', '90%'],
                            content: 'performance/performanceFrom.html'
                        });
                        break;
                    case 'update':
                        var data = checkStatus.data;
                        if (data.length === 0) {
                            layer.msg('请选择一行');
                        } else if (data.length > 1) {
                            layer.msg('只能同时编辑一个');
                        } else {
                            //layer.alert('编辑 [id]：' + checkStatus.data[0].id);
                            //layer.alert(JSON.stringify(data));
                            //layer.msg('录入数据');
                            layer.open({
                                type: 2,
                                title: '业绩分成',
                                shadeClose: true,
                                shade: false,
                                maxmin: true, //开启最大化最小化按钮
                                area: ['90%', '90%'],
                                content: 'performance/performanceFrom.html?performanceId=' + data[0].performanceId
                            });
                        }
                        break;
                    case 'delete':
                        var data = checkStatus.data;
                        if (data.length === 0) {
                            layer.msg('请选择一行');
                        } else {
                            //询问框
                            layer.confirm('是否删除数据?', {
                                btn: ['确定', '取消'] //按钮
                            }, function () {
                                var ids = [];
                                var data = checkStatus.data;
                                for (var i = 0; i < data.length; i++) {
                                    ids.push(data[i].performanceId);
                                }
                                var url = "../performanceAction/deleteAll";
                                var datas = {"ids": ids};
                                $.post(url, datas, function (obj) {
                                    if (obj > 0) {
                                        table2.reload();
                                        layer.msg('删除成功', {icon: 1});
                                    } else {
                                        layer.msg("删除失败")
                                    }
                                });
                            }, function () {
                            })
                        }
                        break;
                }
            }
        );

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            //console.log(obj)
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    var url = "../performanceAction/deleteById";
                    var datas = {"id": data.performanceId};
                    $.post(url, datas, function (obj) {
                        if (obj > 0) {
                            table2.reload();
                            layer.msg('删除成功', {icon: 1});
                        } else {
                            layer.msg("删除失败")
                        }
                    }, "json")
                });
            } else if (obj.event === 'see') {
                layer.open({
                    type: 2,
                    title: '业绩分成',
                    shadeClose: true,
                    shade: false,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['90%', '90%'],
                    content: 'performance/performanceFrom.html?performanceId=' + data.performanceId+'&show=1'
                });
            } else if (obj.event === 'edit') {
                //layer.msg('编辑操作');
                layer.open({
                    type: 2,
                    title: '业绩分成',
                    shadeClose: true,
                    shade: false,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['90%', '90%'],
                    content: 'performance/performanceFrom.html?performanceId=' + data.performanceId
                });
            } else if (obj.event === 'collect') {
                var url = "../typeAction/addOrUpdate";
                var datas = {"typeName": data.clientId}
                $.post(url, datas, function (obj) {
                    if (obj.num == 1) {
                        table2.reload();
                        layer.msg('收藏成功', {icon: 1});
                    } else {
                        layer.msg("已收藏");
                    }
                }, "json")
            } else if (obj.event === 'guide') {
                //layer.msg('开发中。。。', {icon: 2 });

                //layer.msg('约带看');
                layer.open({
                    type: 2,
                    title: '约带看',
                    shadeClose: true,
                    shade: false,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['90%', '90%'],
                    content: 'guide.html?clientId=' + data.clientId
                });
            }
        });
    });
</script>
<script type="text/javascript">
    $(function () {
        var url = "../houseOrClientAction/selectAll";
        $.post(url, null, function (obj) {
            $("#inform").html("");
            $.each(obj, function (index, item) {
                var informId = item.value;
                if (item.revision == 1) {
                    $("#inform").append('<div class="informs" id="' + informId + '" onclick="showInforms(this)">标题：' + item.name + '&nbsp;&nbsp;&nbsp;&nbsp;发布日期：' + createTime(item.dates) + '</div>');
                } else {
                    $("#inform").append('<div class="informs" style="color: red" id="' + informId + '" onclick="showInforms(this)">标题' + item.name + '&nbsp;&nbsp;&nbsp;&nbsp;发布日期：' + createTime(item.dates) + '</div>');
                }
            })
        }, "json")
    });

    function showInforms(houseOrClienId) {
        layui.use(['form', 'table', 'layedit', 'laydate'], function () {
            var table = layui.table
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate
                , form = layui.form;
            layer.open({
                type: 2,
                title: '查看',
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['90%', '90%'],
                content: 'showInform.html?houseClientId=' + houseOrClienId.id
            });
        });
        $("#" + houseOrClienId.id + "").css("color", "black");
    }
</script>
</body>
</html>

